package oa.biz.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import oa.biz.DepartmentBiz;
import oa.biz.DocumentBiz;
import oa.entity.Department;
import oa.entity.Employee;
import oa.mapper.DepartmentMapper;
import oa.mapper.EmployeeMapper;
@Component
public class DepartmentBizImpl implements DepartmentBiz {
	@Autowired
	private DepartmentMapper mapper;
	@Autowired
	private EmployeeMapper empmapper;
	@Override
	public void addDepartment(Department department) {
		mapper.addDepartment(department);
	}

	@Override
	public void removeDepartment(int id) {
		mapper.removeDepartment(id);
	}

	@Override
	public void updateDepartment(Department department) {
		// TODO Auto-generated method stub
		mapper.updateDepartment(department);
	}

	@Override
	public List<Department> getAll() {
		return mapper.getAll();
	}

	@Override
	public Department fetchById(int id) {
		return mapper.fetchById(id);
	}

	@Override
	public List<Department> getAllInLevel() {
		 List<Department> departmentList= mapper.getAllInLevel();
		 List<Department> all=new ArrayList<Department>();
		 for(Department d:departmentList ){
			d.setPid(0);
			all.add(d);
		 }
		 return all;
	}
	public static void main(String[] args) {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-beans.xml");
		DepartmentBiz target =  ctx.getBean(DepartmentBiz.class);
		List<Department> list=target.getAllInLevel();
		for(Department d :list){
			System.out.println(d.getName()+","+d.getPid()+","+d.getId());
		}
	}

}

